/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBean;

import Merlion.CRM.entity.ClientEntity;
import Merlion.CRM.entity.LineEntryEntity;

//import CRM.ProductCRMEntity;
import Merlion.CRM.entity.PricebookEntity;
import Merlion.SCM.entity.ProductEntity;
import Merlion.CRM.bean.SalesLeadModuleRemote;
import Merlion.CRM.bean.SalesOrderProcessingModuleRemote;
import Merlion.util.state.ClientState;
import Merlion.util.state.ContactState;
import Merlion.util.state.LineEntryState;
import Merlion.util.state.ProductState;
import Merlion.util.state.SalesDocumentState;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import javax.servlet.ServletException;
import org.primefaces.event.RowEditEvent;

@ManagedBean(name = "SalesInquiryManagedBean")
@ViewScoped
public class SalesInquiryManagedBean implements Serializable {

   
    private LineEntryState lineEntry = new LineEntryState();
    private List<LineEntryState> lineEntryList = new ArrayList<LineEntryState>();
    private SalesDocumentState newInquiry = new SalesDocumentState();
    private List<SalesDocumentState> inquiryList;
    private SalesDocumentState selectedInquiry;
    private SalesDocumentState[] selectedInquiries;
    private ClientEntity client;
    private String quotationName;
    private String quotationDescription;
    private double discount;
    private List<ProductState> productList;
    private SalesDocumentState selectedViewInquiry;
    private String itemId;
    private Long selectedViewInquiryID;
    private Long selectedPrintInquiryID;
    private Long selectedPrintQuotationID;
    private Long selectedPrintPOID;

    private List<LineEntryState> selectedProductList;
    private List<ClientState> clientList;
    private Date validUntil;
    private ClientState selectedClient;
    private boolean editMode;
    private Long productId;
    private int quantity;
    private double listPrice;
    private String type;
    private PricebookEntity pricebook;
    private List<PricebookEntity> pricebookList;
    private double totalPrice;
    private String pricingType;
    private List<SalesDocumentState> convertedInquiries;
    private List<ContactState> contactList;
    private SalesDocumentState selectedPrintInquiry;
    private SalesDocumentState selectedPrintQuotation;
    private SalesDocumentState selectedPrintPO;
    
    @EJB
    private SalesOrderProcessingModuleRemote sop;
    @EJB
    private SalesLeadModuleRemote smb;

    public String reinit() {
        System.out.println("REINIT line entry");
        lineEntry = new LineEntryState();
        return null;
    }

    public SalesDocumentState getSelectedPrintInquiry() {
        return selectedPrintInquiry;
    }
    
        public Long getSelectedPrintInquiryID() {
        return selectedPrintInquiryID;
    }

    public void setSelectedPrintInquiryID(Long selectedPrintInquiryID) {
        this.selectedPrintInquiryID = selectedPrintInquiryID;
    }

    public void setSelectedPrintInquiry(SalesDocumentState selectedPrintInquiry) {
         System.out.println("SET SELECTED PRINT INQUIRY");
        if(selectedPrintInquiry!=null){System.out.println("INQUIRY NOT NULL");}
        this.selectedPrintInquiry = selectedPrintInquiry;
        System.out.println("ID : "+selectedPrintInquiry.getId());
        this.setSelectedPrintInquiryID(selectedPrintInquiry.getId());
        
        //FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedViewInquiryID",selectedViewInquiryID);
        selectedProductList=sop.viewProductListforSalesDocument(selectedPrintInquiry.getId());
        this.setSelectedProductList(selectedProductList);
        
    }
   
      public void generateSalesInquiryReport(ActionEvent event) throws ServletException{
                 System.out.println("TRY TO GENERATE REPORT ");
        try
        { 
            if(selectedPrintInquiry != null){
            System.out.print("managedbean1");
           //  FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedPrintInquiry", selectedPrintInquiry);
             Long selectedPrintInquiryID = selectedPrintInquiry.getId();
             FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("selectedPrintInquiryID", selectedPrintInquiryID);
             FacesContext.getCurrentInstance().getExternalContext().redirect("http://localhost:8181/MerlionERP-war/salesInquiryServlet");
            System.out.print("managedbean2");
            }else{
               System.out.println("selectedPrintInquiry is null"); 
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }

    public Date getValidUntil() {
        return validUntil;
    }

    public void setValidUntil(Date validUntil) {
        this.validUntil = validUntil;
    }

    public List<ProductState> getProductList() {
        if (productList == null) {
            productList = sop.viewProductList();
        }
        return productList;
    }

    public void setProductList(List<ProductState> productList) {
        this.productList = productList;
    }

    public Long getSelectedViewInquiryID() {
        return selectedViewInquiryID;
    }

    public void setSelectedViewInquiryID(Long selectedViewInquiryID) {
        this.selectedViewInquiryID = selectedViewInquiryID;
    }

    public List<ClientState> getClientList() {
        if (clientList == null) {
            clientList = smb.viewClients();
        }
        return clientList;
    }

    public void setClientList(List<ClientState> clientList) {
        this.clientList = clientList;
    }

    public SalesDocumentState getNewInquiry() {
        return newInquiry;
    }

    public void setNewInquiry(SalesDocumentState newInquiry) {
        this.newInquiry = newInquiry;
    }

    public List<LineEntryState> getSelectedProductList() {
        System.out.println("getSelectedProductList");
        return selectedProductList;
    }

    public void setSelectedProductList(List<LineEntryState> selectedProductList) {
        this.selectedProductList = selectedProductList;
    }

    public SalesDocumentState getSelectedViewInquiry() {
        return selectedViewInquiry;
    }

    public String getItemId() {
        return itemId;
    }

    public void setItemId(String itemId) {
        this.itemId = itemId;
    }

    public void setSelectedViewInquiry(SalesDocumentState selectedViewInquiry) {
        System.out.println("SET SELECTED VIEW INQUIRY");
        if (selectedViewInquiry != null) {
            System.out.println("INQUIRY NOT NULL");
        }
        this.selectedViewInquiry = selectedViewInquiry;
        System.out.println("ID : " + selectedViewInquiry.getId());
        this.setSelectedViewInquiryID(selectedViewInquiry.getId());
        selectedProductList = sop.viewProductListforSalesDocument(selectedViewInquiry.getId());
        this.setSelectedProductList(selectedProductList);
    }

    public void convertedInitView(PhaseEvent event) {
        FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        if (convertedInquiries == null) {
            convertedInquiries = sop.viewConvertedInquiries();
        }
    }

    public List<SalesDocumentState> getConvertedInquiries() {
        return convertedInquiries;
    }

    public void setConvertedInquiries(List<SalesDocumentState> convertedInquiries) {
        this.convertedInquiries = convertedInquiries;
    }

    public List<ContactState> getContactList() {
        if (contactList == null) {
            contactList = smb.viewContacts();
        }
        return contactList;
    }

    public void setContactList(List<ContactState> contactList) {
        this.contactList = contactList;
    }

    public void initView2(PhaseEvent event) {
        FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        if (inquiryList == null) {
            inquiryList = sop.viewSalesInquiries();
        }
    }

    public void initView(PhaseEvent event) {
        FacesContext.getCurrentInstance().getExternalContext().getSession(true);
    }

    public SalesInquiryManagedBean() {

        lineEntry = new LineEntryState();

    }

    public SalesDocumentState[] getSelectedInquiries() {
        return selectedInquiries;
    }

    public void setSelectedInquiries(SalesDocumentState[] selectedInquiries) {
        System.out.println(":::WEB::: SET SELECTED INQUIRIES");
        this.selectedInquiries = selectedInquiries;
    }

    public SalesDocumentState getSelectedInquiry() {
        return selectedInquiry;
    }

    public void setSelectedInquiry(SalesDocumentState selectedInquiry) {
        System.out.println(":::WEB::: SET SELECTED INQUIRY");
        this.selectedInquiry = selectedInquiry;
    }

    public List<SalesDocumentState> getInquiryList() {
        return inquiryList;
    }

    public void setInquiryList(List<SalesDocumentState> inquiryList) {
        this.inquiryList = inquiryList;
    }

    public LineEntryState getLineEntry() {
        System.out.println("Get Line entry");
        return lineEntry;
    }

    public void setLineEntry(LineEntryState lineEntry) {
        System.out.println("Set line entry");

        this.lineEntry = lineEntry;
        productId = lineEntry.getItemId();
        quantity = lineEntry.getQuantity();

    }

    public List<LineEntryState> getLineEntryList() {
        System.out.println("GET LINE ENTRY LIST");
        return lineEntryList;
    }

    public void setLineEntryList(List<LineEntryState> lineEntryList) {
        System.out.println("SET LINE ENTRY LIST");
        this.lineEntryList = lineEntryList;
    }

    public void addSalesInquiry(ActionEvent event) {

        System.out.println(":::WEB::: Add Sales Inquiry2");

        System.out.println("Customer ID is : " + newInquiry.getClientId());

        if (!lineEntryList.isEmpty()) {
            System.out.println("Products not null");
            System.out.println("ID is : " + lineEntryList.get(0).getId());
        }
        System.out.println(":::WEB::: Calling addSalesInquiry2()");
   
        Long contactId = newInquiry.getContactId();
        Date dateIssued = newInquiry.getDateIssued();
        Long clientId = newInquiry.getClientId();
        String description = newInquiry.getDescription();
        String documentName = newInquiry.getDocumentName();
        String epricingType = newInquiry.getPricingType();

        sop.addSalesInquiry(dateIssued, clientId, contactId, lineEntryList, description, documentName, epricingType);

        System.out.println(":::WEB::: Add Sales Inquiry 2 done");

        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("salesInquirySuccessfulRegistration.xhtml");
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }

    public void onEditRow(RowEditEvent event) {

        System.out.println(":::WEB::: On Edit Row");
        SalesDocumentState eDocument = (SalesDocumentState) event.getObject();

        if (eDocument != null) {

            System.out.println(":::WEB::: Edited document not null");
      
            String status = eDocument.getStatus();
            Date eDateIssued = eDocument.getDateIssued();
            Long clientId = eDocument.getClientId();
            Long salesInquiryId = eDocument.getId();
            String clientName = eDocument.getClientName();
            String desc = eDocument.getDescription();
            String documentName = eDocument.getDocumentName();
  
            Long eClientID = eDocument.getClient().getId();
            System.out.println(":::WEB::: Calling Edit Customer");
            sop.editSalesInquiry(salesInquiryId, eDateIssued, eClientID, status, desc, documentName);
        } else {
            System.out.println(":::WEB::: Edited inquiry is null");
        }


    }

    public void handleClientChange() {
        System.out.println("Handle client change");
        if (newInquiry.getClientId() != null) {
            ClientState clState = smb.searchClient(newInquiry.getClientId());
            String bType = clState.getBusinessType();
            this.setType(bType);
            List<ContactState> cList = smb.viewContactsForClients(newInquiry.getClientId());
            this.setContactList(cList);
        }
    }

 
    public ClientEntity getClient() {
        return client;
    }

    public void setClient(ClientEntity client) {
        this.client = client;
    }

    public double getDiscount() {
        return discount;
    }

    public void setDiscount(double discount) {
        this.discount = discount;
    }

    public String getQuotationDescription() {
        return quotationDescription;
    }

    public void setQuotationDescription(String quotationDescription) {
        this.quotationDescription = quotationDescription;
    }

    public String getQuotationName() {
        return quotationName;
    }

    public void setQuotationName(String quotationName) {
        this.quotationName = quotationName;
    }

    public void deleteInquiries() {
        System.out.println(":::WEB::: Delete Inquiries");

        if (selectedInquiries != null) {
            System.out.println(":::WEB::: If selected inquiries not null");
            for (int i = 0; i < selectedInquiries.length; i++) {
                System.out.println("selectedInquiries i: " + i + " - " + selectedInquiries[i].getId());
                sop.deleteSalesInquiry(selectedInquiries[i].getId());
            }
        } else {
            System.out.println(":::WEB::: Selected inquiries are null");
        }

        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("salesInquiries.xhtml");
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }

    public void cancelDelete() {
        for (SalesDocumentState sdState : selectedInquiries) {
            sdState = null;
        }
        if (selectedInquiries == null) {
            System.out.println(":::WEB::: Deletion of inquiries cancelled");

        } else {
            System.out.println(":::WEB::: Deletion of inquiries are not cancelled");
        }

    }

    public void convertSalesInquiry(ActionEvent event) {

        System.out.println(":::WEB::: Convert Inquiry to Quotation");
        if (selectedViewInquiry != null) {
            if (selectedViewInquiry.getStatus().equals("Approved")) {
                Long id = selectedViewInquiry.getId();
                Date cDateIssued = selectedViewInquiry.getDateIssued();
                SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
                String dateStringValidUntil = df.format(validUntil);
                String cDocName = quotationName;
                String cDesc = quotationDescription;
                double cDiscount = discount;

                Date dateValidUntil = new Date();
                try {
                    dateValidUntil = df.parse(dateStringValidUntil);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                Long clientId = selectedViewInquiry.getClientId();
                sop.convertInquiryToQuotation(id, cDiscount, validUntil, cDocName, cDesc);

                try {
                    FacesContext.getCurrentInstance().getExternalContext().redirect("salesInquiries.xhtml");
                } catch (IOException ex) {
                    ex.printStackTrace();
                }


            } else {
                System.out.println("Status not approved!");
                FacesContext context = FacesContext.getCurrentInstance();

                context.addMessage(null, new FacesMessage("Sales Inquiry Conversion not successful!", "Status has not been approved"));

            }
        } else {
            System.out.println(":::WEB::: Selected inquiry is null.");
        }

    }

    public void delete(ActionEvent Event) {

        System.out.println(":::WEB::: Delete Inquiry");

        if (selectedInquiry != null) {
            System.out.println(":::WEB::: Selected inquiry not null");
            Long salesInquiryID = selectedInquiry.getId();
            System.out.println(":::WEB::: Sales Inquiry ID is : " + salesInquiryID);
            sop.deleteSalesInquiry(salesInquiryID);
            System.out.println(":::WEB::: Deletion done");
        } else {
            System.out.println(":::WEB::: Selected inquiry is null");
        }

        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("salesInquiries.xhtml");
        } catch (IOException ex) {
            ex.printStackTrace();
        }


    }

    public ClientState getSelectedClient() {

        return selectedClient;
    }

    public void setSelectedClient(ClientState selectedClient) {
        System.out.println("SET SELECTED CLIENT");
        this.selectedClient = selectedClient;

    }

    public void onEditLineEntry(RowEditEvent event) {

        System.out.println(":::WEB::: On Edit Line Entry");
        LineEntryState line = (LineEntryState) event.getObject();

        if (line != null) {
            System.out.println(":::WEB::: Edited line entry not null");
            int eQuantity = line.getQuantity();
            double price = line.getPrice();
            Long id = line.getId();
            String ePricingType = line.getPricingType();
            System.out.println("ePricing Type");
            double total = sop.getTotalPrice(line, ePricingType);
            line.setTotalPrice(total);
            System.out.println(":::WEB::: Calling Edit Line Entry");
            sop.editLineEntry(id, eQuantity, price, ePricingType);
        } else {
            System.out.println(":::WEB::: Edited line entry is null");
        }

    }

    public boolean isEditMode() {
        return editMode;
    }

    public void setEditMode(boolean editMode) {
        this.editMode = editMode;
    }

    public void save(ActionEvent event) {

        String cDescription = selectedViewInquiry.getDescription();
        Long cClientID = selectedViewInquiry.getClientId();
        Date cDateIssued = selectedViewInquiry.getDateIssued();
        String cStatus = selectedViewInquiry.getStatus();
        Long cId = selectedViewInquiry.getId();
        String cDocName = selectedViewInquiry.getDocumentName();

        sop.editSalesInquiry(cId, cDateIssued, cClientID, cStatus, cDescription, cDocName);
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("salesInquiries.xhtml");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public PricebookEntity getPricebook() {

        return pricebook;
    }

    public void setPricebook(PricebookEntity pricebook) {
        System.out.println("SET PRICEBOOK");

        this.pricebook = pricebook;

    }

    public double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(double totalPrice) {
        System.out.println("Set total price");
        this.totalPrice = totalPrice;
    }

    public String getPricingType() {
        return pricingType;
    }

    public void setPricingType(String pricingType) {
        this.pricingType = pricingType;
        lineEntry.setPricingType(pricingType);
        newInquiry.setPricingType(pricingType);
    }

    public List<PricebookEntity> getPricebookList() {
        System.out.println("GET PRICEBOOK LIST");

        if (pricebookList == null) {
 
            System.out.println("GET from bean");
            pricebookList = sop.getPricebookList();

        }
        return pricebookList;
    }

    public void setPricebookList(List<PricebookEntity> pricebookList) {
        System.out.println("SET pricebook List");
        this.pricebookList = pricebookList;
    }

    public double getListPrice() {
        return listPrice;
    }

    public void setListPrice(double listPrice) {
        System.out.println("SET LIST PRICE");
        this.listPrice = listPrice;
    }

    public void handlePricebookChange() {
        System.out.println("HANDLE PRICEBOOK CHANGE");
        if (lineEntry.getPricebookId() != null) {
            System.out.println("Pricebook not null");
            System.out.println("Type " + type);
            System.out.println("quantity" + lineEntry.getQuantity());
            listPrice = sop.getListPrice(lineEntry.getQuantity(), type, lineEntry.getPricebookId());
            lineEntry.setPrice(listPrice);
            System.out.println(lineEntry.getPrice());
            double total = sop.getTotalPrice(lineEntry, pricingType);
            System.out.println("Total " + total);
            lineEntry.setPricingType(pricingType);
            lineEntry.setTotalPrice(total);
        }
    }

    public void handlePriceChange() {
        System.out.println("Handle price change");
        if (lineEntry.getPrice() != 0) {
            System.out.println("Price " + lineEntry.getPrice());
            double total = sop.getTotalPrice(lineEntry, pricingType);
            lineEntry.setPricingType(pricingType);
            lineEntry.setTotalPrice(total);
        }
    }

    public void onRowEdit(RowEditEvent event) {

        System.out.println(":::WEB::: On Edit Row");
        LineEntryState eLine = (LineEntryState) event.getObject();

        int eQuantity = eLine.getQuantity();
        double newPrice = eLine.getPrice();
        eLine.setPrice(newPrice);
        eLine.setQuantity(eQuantity);

        double total = sop.getTotalPrice(eLine, pricingType);

        eLine.setTotalPrice(total);
 
    }

    public void handleProductChange() {
        System.out.println("HANDLE PRODUCT CHANGE");
        if (lineEntry.getItemId() != null) {
            List<PricebookEntity> list = sop.getPricebook(lineEntry.getItemId());
            System.out.println("Product is not empty");
            this.setPricebookList(list);
            ProductState product = sop.searchProduct(lineEntry.getItemId());
            lineEntry.setItemName(product.getItemName());
            lineEntry.setBasePrice(product.getPrice());
        }
    }

    public Long getProductId() {
        return productId;
    }

    public void setProductId(Long productId) {
        this.productId = productId;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    /**
     * @return the selectedPrintQuotation
     */
    public SalesDocumentState getSelectedPrintQuotation() {
        return selectedPrintQuotation;
    }

    /**
     * @param selectedPrintQuotation the selectedPrintQuotation to set
     */
    public void setSelectedPrintQuotation(SalesDocumentState selectedPrintQuotation) {
        System.out.println("SET SELECTED PRINT QUOTATION");
        if(selectedPrintQuotation!=null){System.out.println("QUOTATION NOT NULL");}
        this.selectedPrintQuotation = selectedPrintQuotation;
        System.out.println("ID : "+selectedPrintQuotation.getId());
        this.setSelectedPrintQuotationID(selectedPrintQuotation.getId());
        
        //FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedViewInquiryID",selectedViewInquiryID);
        selectedProductList=sop.viewProductListforSalesDocument(selectedPrintQuotation.getId());
        this.setSelectedProductList(selectedProductList);
        
    }
    
     public void generateQuotationReport(ActionEvent event) throws ServletException{
                 System.out.println("TRY TO GENERATE REPORT ");
        try
        { 
            if(selectedPrintQuotation != null){
            System.out.print("managedbean1");
           //  FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedPrintInquiry", selectedPrintInquiry);
             Long selectedPrintQuotationID = selectedPrintQuotation.getId();
             FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("selectedPrintQuotationID", selectedPrintQuotationID);
             FacesContext.getCurrentInstance().getExternalContext().redirect("http://localhost:8181/MerlionERP-war/quotationServlet");
            System.out.print("managedbean2");
            }else{
           System.out.println("selectedPrintQuotation is null"); 
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }


    /**
     * @return the selectedPrintQuotationID
     */
    public Long getSelectedPrintQuotationID() {
        return selectedPrintQuotationID;
    }

    /**
     * @param selectedPrintQuotationID the selectedPrintQuotationID to set
     */
    public void setSelectedPrintQuotationID(Long selectedPrintQuotationID) {
        this.selectedPrintQuotationID = selectedPrintQuotationID;
    }

    /**
     * @return the selectedPrintPOID
     */
    public Long getSelectedPrintPOID() {
        return selectedPrintPOID;
    }

    /**
     * @param selectedPrintPOID the selectedPrintPOID to set
     */
    public void setSelectedPrintPOID(Long selectedPrintPOID) {
        this.selectedPrintPOID = selectedPrintPOID;
    }

    public void generatePOReport(ActionEvent event) throws ServletException{
                 System.out.println("TRY TO GENERATE REPORT ");
        try
        { 
            if(selectedPrintPO != null){
            System.out.print("managedbean1");
           //  FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedPrintInquiry", selectedPrintInquiry);
             Long selectedPrintPOID = selectedPrintPO.getId();
             FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("selectedPrintPOID", selectedPrintPOID);
             FacesContext.getCurrentInstance().getExternalContext().redirect("http://localhost:8181/MerlionERP-war/purchaseOrderServlet");
            System.out.print("managedbean2");
            }else{
           System.out.println("selectedPrintpruchaseorder is null"); 
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
    
    /**
     * @return the selectedPrintPO
     */
    public SalesDocumentState getSelectedPrintPO() {
        return selectedPrintPO;
    }

    /**
     * @param selectedPrintPO the selectedPrintPO to set
     */
    public void setSelectedPrintPO(SalesDocumentState selectedPrintPO) {
                   System.out.println("SET SELECTED PRINT PO");
        if(selectedPrintPO!=null){System.out.println("PO NOT NULL");}
        this.selectedPrintPO = selectedPrintPO;
        System.out.println("ID : "+selectedPrintPO.getId());
        this.setSelectedPrintPOID(selectedPrintPO.getId());
        
        //FacesContext.getCurrentInstance().getExternalContext().getFlash().put("selectedViewInquiryID",selectedViewInquiryID);
        selectedProductList=sop.viewProductListforSalesDocument(selectedPrintPO.getId());
        this.setSelectedProductList(selectedProductList);
    }
}
